package com.dwxt.sport.business.controller;

import com.dwxt.common.base.BaseResult;
import com.dwxt.sport.business.entity.SportsTraining;
import com.dwxt.sport.business.entity.SportsTrainingDetails;
import com.dwxt.sport.business.service.SportsTrainingService;
import com.dwxt.sport.business.vo.sportsTraining.InsertOrUpdateSportsTrainingDetailsVo;
import com.dwxt.sport.business.vo.sportsTraining.InsertOrUpdateSportsTrainingVo;
import com.dwxt.sport.business.vo.sportsTraining.SelectSportsTrainingVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 体育培训
 *
 * @author Kuang.JiaZhuo
 * @date 2020-07-31 10:45
 */
@RestController
@RequestMapping("/sportsTraining")
@Api(tags={"体育培训业务接口"})
public class SportsTrainingController {

    @Resource
    SportsTrainingService sportsTrainingService;

    @ApiOperation(value = "新增或修改体育培训", notes = "新增或修改体育培训", response = Integer.class)
    @PostMapping("/back/insertOrUpdateSportsTraining")
    public BaseResult insertOrUpdateSportsTraining(InsertOrUpdateSportsTrainingVo insertOrUpdateVo){
        int result = this.sportsTrainingService.insertOrUpdateSportsTraining(insertOrUpdateVo);
        return BaseResult.ok(result);
    }

    @ApiOperation(value = "获取体育培训列表", notes = "按条件查询体育培训列表(带分页)", response = SportsTraining.class)
    @PostMapping("/back/selectSportsTrainingByCriteria")
    public BaseResult selectSportsTrainingByCriteria(SelectSportsTrainingVo selectVo){
        PageInfo<SportsTraining> pageInfo = this.sportsTrainingService.selectSportsTrainingByCriteria(selectVo);
        return BaseResult.ok(pageInfo);
    }

    @ApiOperation(value = "删除体育培训", notes = "根据ids批量删除体育培训", response= Integer.class)
    @PostMapping(value = "/back/deleteSportsTrainingByIds")
    public BaseResult deleteSportsTrainingByIds(@ApiParam(value = "要删除的id字符串,以英文逗号隔开", required = true) @RequestParam String ids){
        int result = this.sportsTrainingService.deleteSportsTrainingByIds(ids);
        return BaseResult.ok(result);
    }


    /******************************************************************  关联设备  ******************************************************************************/

    @ApiOperation(value = "新增 或 更新 体育培训详情", notes = "新增 或 更新 体育培训详情", response = Integer.class)
    @PostMapping("/back/insertOrUpdateSportsTrainingDetails")
    public BaseResult insertOrUpdateSportsTrainingDetails(InsertOrUpdateSportsTrainingDetailsVo insertOrUpdateVo){
        int result = this.sportsTrainingService.insertOrUpdateSportsTrainingDetails(insertOrUpdateVo);
        return BaseResult.ok(result);
    }

    @ApiOperation(value = "删除 体育培训详情", notes = "根据ids批量删除 体育培训详情", response= Integer.class)
    @PostMapping(value = "/back/deleteSportsTrainingDetailsByIds")
    public BaseResult deleteSportsTrainingDetailsByIds(@ApiParam(value = "要删除的id字符串,以英文逗号隔开", required = true) @RequestParam String ids){
        int result = this.sportsTrainingService.deleteSportsTrainingDetailsByIds(ids);
        return BaseResult.ok(result);
    }

    @ApiOperation(value = "查询【体育培训】的设备列表", notes = "根据【体育培训】的id查询详情(详情列表带分页)", response= SportsTrainingDetails.class)
    @PostMapping(value = "/back/selectSportsTrainingDetailsByPage")
    public BaseResult selectSportsTrainingDetailsByPage(@ApiParam(value = "体育培训关联id", required = true) @RequestParam String id,
                                            @ApiParam(value = "起始页", required = true) @RequestParam Integer pageNum,
                                            @ApiParam(value = "页大小", required = true) @RequestParam Integer pageSize){
        String sportsTrainingId = id;
        PageInfo<SportsTrainingDetails> pageInfo = this.sportsTrainingService.selectSportsTrainingDetailsByPage(pageNum,pageSize,sportsTrainingId);
        return BaseResult.ok(pageInfo);
    }
}
